var GameData = require('../module/gameData')();
cc.Class({
    extends: cc.Component,

    properties: {
        text1: cc.Label,
        text2: cc.Label,
        text3: cc.Label,
        f_sp: cc.Sprite,
        fish: cc.SpriteAtlas,
        particle1: cc.ParticleSystem,
        particle2: cc.ParticleSystem,
        cb: dragonBones.ArmatureDisplay,
    },
    // LIFE-CYCLE CALLBACKS:
    onLoad() {

    },
    cbPlay() {
        switch (this.cb_State) {
            case "ZK":
                this.cb.playAnimation("CX", 0);
                break;
            case "CX":
                break;
        }
    },
    initText() {
        this.isbtn = false;
        this.fishData = GameData.getlocalData("fishData");
        this.text1.string = GameData.gameText.home.text1;
        this.text2.string = GameData.gameText.home.btn_text;
        this.text3.string = GameData.gameText.home.text2;
        console.log(this.fishData.handbook.newfish[0]);

        this.id = this.fishData.handbook.newfish[0];
        this.f_sp.node.getComponent(cc.Sprite).spriteFrame = this.fish.getSpriteFrame("f" + (this.id + 1));
        for(var a=0;a<this.fishData.handbook.oldfish.length;a++){
            if(typeof  this.fishData.handbook.oldfish[a]!="number"){
                this.fishData.handbook.oldfish.splice(a,1);
                a--;
            }
        }
        GameData.savelocalData(this.fishData);
        var _num2 = GameData.upgradeData.box[this.fishData.upgrade.box - 1].Allnum;
        var _num1 = this.fishData.handbook.oldfish.length;

        if (_num2 >_num1) {

            // GameData.gameHome.l1.string = this.fishData.handbook.oldfish.length+ "";
            this.text3.node.active = false;
        } else {
            this.text3.node.active = true;
            this.isbtn = true;
        }
    },
    onEnable() {
        this.node.getChildByName("bg").setScale(0.1, 0.1);
        this.initText();
        var that = this;
        var _s = 1.2;
        var _s1 = 0.9;
        this.node.getChildByName("bg").runAction(
            cc.sequence(
                cc.scaleTo(0.3, _s),
                cc.scaleTo(0.15, _s1),
                cc.callFunc(function () {
                    that.begin = true;
                    that.particle2.resetSystem();
                })
            )
        );
        this.cb.addEventListener(dragonBones.EventObject.LOOP_COMPLETE, this.cbPlay, this);
        this.cb_State = "ZK"

    },
    selectBtn() {
        this.particle2.stopSystem();
        this.particle1.stopSystem();
        this.node.active = false;
        if (this.isbtn) {
            GameData.gamhomeshow = true;
            GameData.gameUpgrade = 1;
            cc.director.preloadScene("upgrade", function () {
                cc.director.loadScene("upgrade");
            });
        } else {
            this.fishData.handbook.oldfish.push(this.id);
            this.fishData.handbook.newfish.splice(0, 1);
            GameData.savelocalData(this.fishData);
            GameData.gameHome.createNewFish(this.id);
        }

    },

    start() {

    },

    // update (dt) {},
});
